using Perfect.Marshal;
using System.Xml;

namespace editor
{
namespace cfg.map
{
[System.Serializable]
public  class Vector4 :   cfg.EditorReadWriter 
 {

    public float x ;
     public float y ;
     public float z ;
     public float w ;
     


    public const int TYPE_ID = 198261269;

    public override int GetTypeId() {
        return TYPE_ID;
    }


    public override void MarshalCompatible(Perfect.Marshal.Octets os) {
        os.WriteSize(4);
        os.WriteSize(Tag.FLOAT | (1 << Tag.TAG_SHIFT));  os.WriteFloat(x);  
         os.WriteSize(Tag.FLOAT | (2 << Tag.TAG_SHIFT));  os.WriteFloat(y);  
         os.WriteSize(Tag.FLOAT | (3 << Tag.TAG_SHIFT));  os.WriteFloat(z);  
         os.WriteSize(Tag.FLOAT | (4 << Tag.TAG_SHIFT));  os.WriteFloat(w);  
         
    }

    public override void UnmarshalCompatible(Perfect.Marshal.Octets os) {
        for (int _var_num_ = os.ReadSize(); _var_num_-- > 0; ) {
            int _id_ = os.ReadSize();
            switch (_id_)
            {
            case (Tag.FLOAT | (1 << Tag.TAG_SHIFT)):   x = os.ReadFloat(); break;  
             case (Tag.FLOAT | (2 << Tag.TAG_SHIFT)):   y = os.ReadFloat(); break;  
             case (Tag.FLOAT | (3 << Tag.TAG_SHIFT)):   z = os.ReadFloat(); break;  
             case (Tag.FLOAT | (4 << Tag.TAG_SHIFT)):   w = os.ReadFloat(); break;  
             
            default: Tag.SkipUnknownField(_id_, os); break;
            }
         }
    }
    public override void MarshalXml(XmlWriter ele)
    {
        ele.WriteAttributeString("type", "Vector4");
        ele.WriteStartElement("x"); ele.WriteAttributeString("id", "1"); ele.WriteFloat(x); ele.WriteEndElement();
         ele.WriteStartElement("y"); ele.WriteAttributeString("id", "2"); ele.WriteFloat(y); ele.WriteEndElement();
         ele.WriteStartElement("z"); ele.WriteAttributeString("id", "3"); ele.WriteFloat(z); ele.WriteEndElement();
         ele.WriteStartElement("w"); ele.WriteAttributeString("id", "4"); ele.WriteFloat(w); ele.WriteEndElement();
         
    }

    public override void UnmarshalXml(XmlElement ele)
    {
        foreach (XmlElement e in ele.GetChildren())
        {
            if (int.TryParse(ele.GetAttribute("id"), out var _id_))
            {
                switch (_id_)
                {
                case 1:  x = ele.ReadFloat(); break; 
                 case 2:  y = ele.ReadFloat(); break; 
                 case 3:  z = ele.ReadFloat(); break; 
                 case 4:  w = ele.ReadFloat(); break; 
                 
                default: break;
                }
            }
            else
            {
                switch (e.Name)
                {
                case "x":  x = ele.ReadFloat(); break; 
                 case "y":  y = ele.ReadFloat(); break; 
                 case "z":  z = ele.ReadFloat(); break; 
                 case "w":  w = ele.ReadFloat(); break; 
                 
                default: break;
                }
            }
        }
    }
}
}
}
